package com.net.xpay.partner.controller.partner;


import com.net.common.model.ResultData;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.partner.Partner;
import com.net.xpay.common.domain.partner.PartnerUserFilings;
import com.net.xpay.common.manager.partner.PartnerUserFilingsManager;
import com.net.xpay.common.model.search.PartnerUserFilingsSearchModel;
import com.net.xpay.common.model.PartnerUserFilingsSubmitModel;
import com.net.xpay.common.service.PartnerUserFilingsService;
import com.net.xpay.core.utils.BeanCopierUtil;
import com.net.xpay.partner.secutiry.RequestUser;
import com.net.xpay.partner.vo.PartnerUserFilingsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 2019/4/1 14:45

 */
@Slf4j
@RestController
@RequestMapping("/partner/partner-user-filings")
@Api(tags = "运营/开户申请", description = "运营 开户申请 net")
public class PartnerUserFilingsController {

    @Autowired
    private PartnerUserFilingsManager partnerUserFilingsManager;

    @Autowired
    private PartnerUserFilingsService partnerUserFilingsService;


    @ApiOperation("开户申请")
    @PostMapping("/submit")
    @ResponseBody
    public ResultData<PartnerUserFilings> submitUserFilings(@ApiIgnore @RequestUser Partner partner, @RequestBody PartnerUserFilingsSubmitModel model) {
        PartnerUserFilings filings = partnerUserFilingsService.submitPartnerUserFilings(partner, model);

        return new ResultData<>(filings);
    }


    @ApiOperation("开户申请分页搜索")
    @PostMapping("/search")
    @ResponseBody
    public ResultPagedList<PartnerUserFilingsVo> search(@ApiIgnore @RequestUser Partner partner, @RequestBody PartnerUserFilingsSearchModel searchModel) {
        searchModel.setPartnerId(partner.getId());
        List<PartnerUserFilings> records = partnerUserFilingsManager.search(searchModel);
        long count = partnerUserFilingsManager.searchCount(searchModel);

        List<PartnerUserFilingsVo> partnerUserFilingsVos = BeanCopierUtil.batchCopy(PartnerUserFilings.class, PartnerUserFilingsVo.class, records);

        return new ResultPagedList<>(partnerUserFilingsVos, count, searchModel);
    }


}
